﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using Data;
using System.Resources;

namespace PracticeProject
{
    public partial class Form1 : Form
    {
        ElementCollection data;
        List<Goal> Goals;
        List<Activity> Activities;
        public Form1()
        {
            InitializeComponent();
            data = ElementCollection.OpenCollectionFromXml( );
            
        }

       
        private void Form1_Load(object sender, EventArgs e)
        {
            SetLists();
        }

        private void Form1_Closed(object sender, EventArgs e)
        {
           
        }

        private void menuItem3_Click(object sender, EventArgs e)
        {
            Adding_Form f = new Adding_Form();
            f.ShowDialog();
            SetLists();
        }

        private void Form1_Deactivate(object sender, EventArgs e)
        {
           
        }

        private void menuItem4_Click(object sender, EventArgs e)
        {
            Adding_Activity_Form f = new Adding_Activity_Form();
            f.ShowDialog();
            SetLists();
        }

        void SetLists()
        {
            
            Goals = data.GetGoals(DTSteToLook.Value);
            Activities = data.GetActivities(DTSteToLook.Value);
            PnlGoals.Controls.Clear();
            for(int i = 0; i<Goals.Count; i++)
            {
                LinkLabel l = new LinkLabel();
                l.Text = Goals[i].Description;
                
                l.Location = new Point(10, 17 * i);
                l.Click += new EventHandler(l_Click);
                switch (Goals[i].Priority)
                {
                    case 0:
                        l.ForeColor = Color.Chocolate;
                        
                        break;
                    case 1:
                        l.ForeColor = Color.Black;
                        break;
                    case 2:
                        l.ForeColor = Color.Green;
                        break;
                }
                
                
                
                PnlGoals.Controls.Add(l);

            }
            PnlActivities.Controls.Clear();
            for (int i = 0; i < Activities.Count; i++)
            {
                LinkLabel l = new LinkLabel();
                l.Text = Activities[i].Description;
                l.ForeColor = Color.Black;
                l.Location = new Point(10, 17 * i);
                l.Click += new EventHandler(l_Click1);
                PnlActivities.Controls.Add(l);
            }
            
        }

        void l_Click(object sender, EventArgs e)
        {
            int i = PnlGoals.Controls.IndexOf((Control)sender);
            GoalViewForm f = new GoalViewForm(Goals[i]);
            f.ShowDialog();
            SetLists();
        }

        void l_Click1(object sender, EventArgs e)
        {
            int i = PnlActivities.Controls.IndexOf((Control)sender);
            ActViewForm f = new ActViewForm(Activities[i]);
            f.ShowDialog();
            SetLists();
        }
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
           
            
        }

        

        private void DTSteToLook_ValueChanged(object sender, EventArgs e)
        {
            SetLists();
        }

        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {

        }
    }
}